package com.boot.web;

import com.boot.domian.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Chunsheng.Zhang
 * @date 2021/3/10 18:12
 * @description : TODO
 */
@Slf4j
@Controller
public class LoginController {



    @RequestMapping("/login-success")
    @ResponseBody
    public String loginSuccess(){
        return "登录成功！";
    }




    @RequestMapping("/toIndex")
    public String toIndex(){
        log.info("访问到了index");
        return "index";
    }




    @RequestMapping("/")
    public String toLogin(){
        log.info("访问到了loginController");
        return "login";
    }


    @RequestMapping("/logout")
    public String logout(HttpServletRequest request){
        request.getSession().removeAttribute("currentUser");
        return "login";
    }



    @RequestMapping("/login")
    public String login(String username, String password, HttpServletRequest request){

        if (username != null && password != null) {
            User user = new User();
            user.setUsername(username);
            user.setUsername(password);
            request.getSession().setAttribute("currentUser",user);

            return "index";
        }


        return "login";

    }




}
